/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ufrgs.inf.delphos.extraction.model.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENamedElementImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;

import ufrgs.inf.delphos.extraction.model.DConfig;
import ufrgs.inf.delphos.extraction.model.DPackage;
import ufrgs.inf.delphos.extraction.model.DPolicy;
import ufrgs.inf.delphos.extraction.model.DSystem;
import ufrgs.inf.delphos.extraction.model.DelphosSystemModelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>DSystem</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ufrgs.inf.delphos.extraction.model.impl.DSystemImpl#getPoliciesList <em>Policies</em>}</li>
 *   <li>{@link ufrgs.inf.delphos.extraction.model.impl.DSystemImpl#getPackagesList <em>Packages</em>}</li>
 *   <li>{@link ufrgs.inf.delphos.extraction.model.impl.DSystemImpl#getConfigFilesList <em>Config Files</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DSystemImpl extends ENamedElementImpl implements DSystem {
	/**
	 * The cached value of the '{@link #getPoliciesList() <em>Policies</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPoliciesList()
	 * @generated
	 * @ordered
	 */
	protected EList<DPolicy> policies;

	/**
	 * The empty value for the '{@link #getPolicies() <em>Policies</em>}' array accessor.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPolicies()
	 * @generated
	 * @ordered
	 */
	protected static final DPolicy[] POLICIES_EEMPTY_ARRAY = new DPolicy [0];

	/**
	 * The cached value of the '{@link #getPackagesList() <em>Packages</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPackagesList()
	 * @generated
	 * @ordered
	 */
	protected EList<DPackage> packages;

	/**
	 * The empty value for the '{@link #getPackages() <em>Packages</em>}' array accessor.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPackages()
	 * @generated
	 * @ordered
	 */
	protected static final DPackage[] PACKAGES_EEMPTY_ARRAY = new DPackage [0];

	/**
	 * The cached value of the '{@link #getConfigFilesList() <em>Config Files</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getConfigFilesList()
	 * @generated
	 * @ordered
	 */
	protected EList<DConfig> configFiles;

	/**
	 * The empty value for the '{@link #getConfigFiles() <em>Config Files</em>}' array accessor.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getConfigFiles()
	 * @generated
	 * @ordered
	 */
	protected static final DConfig[] CONFIG_FILES_EEMPTY_ARRAY = new DConfig [0];

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DSystemImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return DelphosSystemModelPackage.Literals.DSYSTEM;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DPolicy[] getPolicies() {
		if (policies == null || policies.isEmpty()) return POLICIES_EEMPTY_ARRAY;
		BasicEList<DPolicy> list = (BasicEList<DPolicy>)policies;
		list.shrink();
		return (DPolicy[])list.data();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DPolicy getPolicies(int index) {
		return getPoliciesList().get(index);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getPoliciesLength() {
		return policies == null ? 0 : policies.size();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPolicies(DPolicy[] newPolicies) {
		((BasicEList<DPolicy>)getPoliciesList()).setData(newPolicies.length, newPolicies);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPolicies(int index, DPolicy element) {
		getPoliciesList().set(index, element);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DPolicy> getPoliciesList() {
		if (policies == null) {
			policies = new EObjectContainmentEList<DPolicy>(DPolicy.class, this, DelphosSystemModelPackage.DSYSTEM__POLICIES);
		}
		return policies;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DPackage[] getPackages() {
		if (packages == null || packages.isEmpty()) return PACKAGES_EEMPTY_ARRAY;
		BasicEList<DPackage> list = (BasicEList<DPackage>)packages;
		list.shrink();
		return (DPackage[])list.data();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DPackage getPackages(int index) {
		return getPackagesList().get(index);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getPackagesLength() {
		return packages == null ? 0 : packages.size();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPackages(DPackage[] newPackages) {
		((BasicEList<DPackage>)getPackagesList()).setData(newPackages.length, newPackages);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPackages(int index, DPackage element) {
		getPackagesList().set(index, element);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DPackage> getPackagesList() {
		if (packages == null) {
			packages = new EObjectContainmentEList<DPackage>(DPackage.class, this, DelphosSystemModelPackage.DSYSTEM__PACKAGES);
		}
		return packages;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DConfig[] getConfigFiles() {
		if (configFiles == null || configFiles.isEmpty()) return CONFIG_FILES_EEMPTY_ARRAY;
		BasicEList<DConfig> list = (BasicEList<DConfig>)configFiles;
		list.shrink();
		return (DConfig[])list.data();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DConfig getConfigFiles(int index) {
		return getConfigFilesList().get(index);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getConfigFilesLength() {
		return configFiles == null ? 0 : configFiles.size();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setConfigFiles(DConfig[] newConfigFiles) {
		((BasicEList<DConfig>)getConfigFilesList()).setData(newConfigFiles.length, newConfigFiles);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setConfigFiles(int index, DConfig element) {
		getConfigFilesList().set(index, element);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DConfig> getConfigFilesList() {
		if (configFiles == null) {
			configFiles = new EObjectContainmentEList<DConfig>(DConfig.class, this, DelphosSystemModelPackage.DSYSTEM__CONFIG_FILES);
		}
		return configFiles;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case DelphosSystemModelPackage.DSYSTEM__POLICIES:
				return ((InternalEList<?>)getPoliciesList()).basicRemove(otherEnd, msgs);
			case DelphosSystemModelPackage.DSYSTEM__PACKAGES:
				return ((InternalEList<?>)getPackagesList()).basicRemove(otherEnd, msgs);
			case DelphosSystemModelPackage.DSYSTEM__CONFIG_FILES:
				return ((InternalEList<?>)getConfigFilesList()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case DelphosSystemModelPackage.DSYSTEM__POLICIES:
				return getPoliciesList();
			case DelphosSystemModelPackage.DSYSTEM__PACKAGES:
				return getPackagesList();
			case DelphosSystemModelPackage.DSYSTEM__CONFIG_FILES:
				return getConfigFilesList();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case DelphosSystemModelPackage.DSYSTEM__POLICIES:
				getPoliciesList().clear();
				getPoliciesList().addAll((Collection<? extends DPolicy>)newValue);
				return;
			case DelphosSystemModelPackage.DSYSTEM__PACKAGES:
				getPackagesList().clear();
				getPackagesList().addAll((Collection<? extends DPackage>)newValue);
				return;
			case DelphosSystemModelPackage.DSYSTEM__CONFIG_FILES:
				getConfigFilesList().clear();
				getConfigFilesList().addAll((Collection<? extends DConfig>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case DelphosSystemModelPackage.DSYSTEM__POLICIES:
				getPoliciesList().clear();
				return;
			case DelphosSystemModelPackage.DSYSTEM__PACKAGES:
				getPackagesList().clear();
				return;
			case DelphosSystemModelPackage.DSYSTEM__CONFIG_FILES:
				getConfigFilesList().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case DelphosSystemModelPackage.DSYSTEM__POLICIES:
				return policies != null && !policies.isEmpty();
			case DelphosSystemModelPackage.DSYSTEM__PACKAGES:
				return packages != null && !packages.isEmpty();
			case DelphosSystemModelPackage.DSYSTEM__CONFIG_FILES:
				return configFiles != null && !configFiles.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //DSystemImpl
